#!/bin/sh
#
# @name Heterogeneous 10PWM Special Frame
#
# @type Octorotor x
# @class Copter
#
# @maintainer
#

#

# Load custom heterogeneous mixer
set MIXER hetero_10pwm
set VEHICLE_TYPE mc

# EKF2 configuration for sensor fusion with minimal requirements
param set-default EKF2_EN 1
param set-default EKF2_MULTI_IMU 1
param set-default SENS_IMU_MODE 1
param set-default EKF2_MAG_TYPE 0
param set-default EKF2_GPS_CTRL 0
param set-default EKF2_BARO_CTRL 0
param set-default EKF2_HGT_REF 0
param set-default EKF2_RNG_CTRL 0
param set-default EKF2_OPTICAL_CTRL 0
param set-default EKF2_EV_POS_CTRL 0
param set-default EKF2_EV_YAW_CTRL 0
param set-default EKF2_WIND_CTRL 0
# Disable compass completely
param set-default SENS_MAG_MODE 0

# Skip ALL safety checks for direct arming - COMPLETE DISABLE
param set-default COM_ARM_WO_GPS 1
param set-default COM_ARM_MAG_ANG 180
param set-default COM_ARM_EKF_AB 1.0
param set-default COM_ARM_EKF_GB 1.0
param set-default COM_ARM_EKF_PB 1.0
param set-default COM_ARM_EKF_YAW 1.0
param set-default COM_ARM_IMU_ACC 1.0
param set-default COM_ARM_IMU_GYR 1.0
param set-default COM_ARM_MAG_STR 0.0
param set-default COM_ARM_SWISBTN 0
param set-default COM_ARM_CHK_DRV 0
param set-default COM_ARM_CHK_ESCS 0
param set-default COM_ARM_CHK_MAG 0
param set-default COM_ARM_CHK_ACC 0
param set-default COM_ARM_CHK_GYR 0
param set-default COM_ARM_CHK_BARO 0
param set-default COM_ARM_CHK_AIRSPD 0
param set-default COM_ARM_CHK_RC 0
param set-default COM_ARM_CHK_GPS 0
param set-default COM_ARM_CHK_IMU 0
param set-default COM_ARM_CHK_SYSTEM 0
param set-default COM_ARM_CHK_PARAM 0
# All bypass checks - COMPLETE SET
param set-default CBRK_SUPPLY_CHK 894281
param set-default CBRK_IO_SAFETY 22027
param set-default CBRK_USB_CHK 197848
param set-default CBRK_FLIGHTTERM 121212
param set-default CBRK_AIRSPD_CHK 162128
param set-default CBRK_MAG_CHK 1
param set-default CBRK_GPSFAIL 240024
param set-default CBRK_RATE_CTRL 118211
param set-default CBRK_VELPOSERR 203254
# Disable ALL arming checks - COMPLETE DISABLE
param set-default ARMING_CHECK 0
param set-default MAV_SYS_ID 1
# Force system health to pass - COMPLETE OVERRIDE
param set-default SYS_HAS_MAG 0
param set-default SYS_HAS_GPS 0
param set-default SYS_HAS_BARO 0
param set-default SYS_HAS_IMU 1
param set-default SYS_HAS_RC 1
param set-default SYS_HAS_NUM_DIST 0
param set-default SYS_HAS_AIRSPD 0
param set-default SYS_HAS_OPTFLOW 0
param set-default SYS_HAS_EV 0
# Disable all sensor preflight checks
param set-default COM_PREARM_MODE 0
param set-default COM_ARM_CHK_ALL 0
param set-default COM_ARM_IMBAL 1.0
param set-default COM_ARM_EKF_HGT 1.0
param set-default COM_ARM_EKF_VEL 1.0
param set-default COM_ARM_EKF_POS 1.0
# Force system to report healthy
param set-default SYS_FAILURE_EN 0
param set-default CBRK_FAILSAFE 0
# Additional critical unlock parameters
param set-default COM_ARM_IMU_DIFF 1.0
param set-default COM_ARM_EKF_ALT 1.0
param set-default COM_ARM_EKF_HDG 1.0
param set-default COM_ARM_EKF_XY 1.0
param set-default COM_ARM_EKF_VXY 1.0
param set-default COM_ARM_EKF_VZ 1.0
param set-default COM_ARM_EKF_HGT 1.0
param set-default COM_ARM_EKF_YAW 1.0
# Force all checks to pass
param set-default COM_ARM_ALLOW 1
param set-default COM_ARM_AUTH 0
param set-default COM_ARM_SWITCH 0
# Disable safety switch requirement
param set-default CBRK_SAFETY 22027

# Allow arming with throttle not at minimum (disable throttle safety check)
param set-default COM_RC_OVERRIDE 1

# Power management with minimal checks (3S battery)
# Both prefixed and non-prefixed parameters for compatibility
param set-default BAT1_N_CELLS 3
param set-default BATNCELLS 3
param set-default BAT1_V_CHARGED 4.2000
param set-default BATVCHARGED 4.2000
param set-default BAT1_V_EMPTY 3.5000
param set-default BATVEMPTY 3.5000
param set-default BAT1_V_DIV 10.177939394
param set-default BAT1_A_PER_V 15.391030303
param set-default BAT_CRIT_THR 0.0500
param set-default BAT_EMERGEN_THR 0.0100
param set-default BAT_LOW_THR 0.1000
param set-default COM_ARM_BAT_MIN 0.0000
param set-default COM_LOW_BAT_ACT 0
param set-default COM_POWER_COUNT 0
param set-default BAT_FS_CRT_ACT 0
param set-default BAT_FS_LOW_ACT 0
param set-default BAT_FS_EMERGEN_ACT 0

# Custom parameters for heterogeneous control
param set-default CA_AIRFRAME 15
param set-default CA_ROTOR_COUNT 10

# Motor configuration for upward thrust (Motors 1,2)
param set-default CA_ROTOR0_PX 0.5
param set-default CA_ROTOR0_PY 0.5
param set-default CA_ROTOR0_KZ 1.0
param set-default CA_ROTOR0_KM 0.0

param set-default CA_ROTOR1_PX -0.5
param set-default CA_ROTOR1_PY 0.5
param set-default CA_ROTOR1_KZ 1.0
param set-default CA_ROTOR1_KM 0.0

# Motor configuration for downward thrust (Motors 3,4)
param set-default CA_ROTOR2_PX 0.5
param set-default CA_ROTOR2_PY -0.5
param set-default CA_ROTOR2_KZ -1.0
param set-default CA_ROTOR2_KM 0.0

param set-default CA_ROTOR3_PX -0.5
param set-default CA_ROTOR3_PY -0.5
param set-default CA_ROTOR3_KZ -1.0
param set-default CA_ROTOR3_KM 0.0

# Motor configuration for left rotation (Motors 5,6)
param set-default CA_ROTOR4_PX 1.0
param set-default CA_ROTOR4_PY 0.0
param set-default CA_ROTOR4_KZ 0.0
param set-default CA_ROTOR4_KM -0.1

param set-default CA_ROTOR5_PX -1.0
param set-default CA_ROTOR5_PY 0.0
param set-default CA_ROTOR5_KZ 0.0
param set-default CA_ROTOR5_KM -0.1

# Motor configuration for right rotation (Motors 7,8)
param set-default CA_ROTOR6_PX 0.0
param set-default CA_ROTOR6_PY 1.0
param set-default CA_ROTOR6_KZ 0.0
param set-default CA_ROTOR6_KM 0.1

param set-default CA_ROTOR7_PX 0.0
param set-default CA_ROTOR7_PY -1.0
param set-default CA_ROTOR7_KZ 0.0
param set-default CA_ROTOR7_KM 0.1

# Motor configuration for fan direction (Motor 9)
param set-default CA_ROTOR8_PX 0.0
param set-default CA_ROTOR8_PY 0.0
param set-default CA_ROTOR8_KZ 0.0
param set-default CA_ROTOR8_KM 1.0

# Servo 13 configuration (AUX OUT 5)
param set-default CA_SV0_PX 0.0
param set-default CA_SV0_PY 0.0
param set-default CA_SV0_KM 0.0
param set-default CA_SV0_ANGLE 180.0

# Servo 14 configuration (AUX OUT 6)
param set-default CA_SV1_PX 0.0
param set-default CA_SV1_PY 0.0
param set-default CA_SV1_KM 0.0
param set-default CA_SV1_ANGLE 180.0

# Ensure servo count is 2
param set-default CA_SV_COUNT 2

# Motor configuration for main thrust (Motor 10)
param set-default CA_ROTOR9_PX 0.0
param set-default CA_ROTOR9_PY 0.0
param set-default CA_ROTOR9_KZ 1.0
param set-default CA_ROTOR9_KM 0.0

# Custom mixing parameters
param set-default MC_ROLLRATE_MAX 180
param set-default MC_PITCHRATE_MAX 180
param set-default MC_YAWRATE_MAX 90
param set-default MC_ACRO_R_MAX 180
param set-default MC_ACRO_P_MAX 180
param set-default MC_ACRO_Y_MAX 90

# Throttle parameters for special control logic
param set-default MPC_THR_HOVER 0.5
param set-default MPC_THR_MAX 0.9
param set-default MPC_THR_MIN 0.0

# PWM output configuration to ensure motors stop when throttle is zero
param set-default PWM_MAIN_MIN 1000
param set-default PWM_MAIN_MAX 2000
param set-default PWM_MAIN_DISARM 900
param set-default PWM_MAIN_FAIL 900

# Disable all automatic disarming to keep armed state unless manually disarmed by RC
param set-default COM_DISARM_LAND 0      # Disable auto-disarm after landing
param set-default COM_DISARM_PRFLT 0     # Disable auto-disarm after preflight check failure
param set-default COM_DISARM_MAN 0       # Disable manual disarm timeout
param set-default COM_POSCTL_NAV 0       # Disable position control navigation disarm
param set-default COM_OBL_ACT 0          # Disable obstacle avoidance disarm
param set-default COM_OBL_RC_ACT 0       # Disable RC obstacle avoidance disarm

# Set mixer
set MIXER hetero_10pwm

# Start hetero_passthrough module for direct control (bypass all standard controllers)
#hetero_passthrough start

# Configure 11th and 12th servos for 500-2500μs range
param set-default PWM_MAIN_MIN11 500
param set-default PWM_MAIN_MAX11 2500
param set-default PWM_MAIN_TRIM11 1500
param set-default PWM_MAIN_FUNCTION11 41

param set-default PWM_MAIN_MIN12 500
param set-default PWM_MAIN_MAX12 2500
param set-default PWM_MAIN_TRIM12 1500
param set-default PWM_MAIN_FUNCTION12 44

# Configure 13th and 14th servos for 500-2500μs range
param set-default PWM_MAIN_MIN13 500
param set-default PWM_MAIN_MAX13 2500
param set-default PWM_MAIN_TRIM13 1500
param set-default PWM_MAIN_FUNCTION13 45

param set-default PWM_MAIN_MIN14 500
param set-default PWM_MAIN_MAX14 2500
param set-default PWM_MAIN_TRIM14 1500
param set-default PWM_MAIN_FUNCTION14 46
